package com.liuya.db.sql;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * 分组
 */
public class GroupBy implements SQLElement, java.io.Serializable  {
	private ArrayList columns = new ArrayList();

	public String toSQL() {
		if (columns.size() == 0) {
			return "";
		}
		StringBuffer buf = new StringBuffer();
		buf.append("\n").append(" GROUP BY ");
		Iterator itr = columns.iterator();
		Column column = (Column) itr.next();
		buf.append(column.toSQL());
		while (itr.hasNext()) {
			column = (Column) itr.next();
			buf.append(",").append(column.toSQL());
		}
		buf.append(" ");
		return buf.toString();
	}

	public ArrayList getColumns() {
		return columns;
	}

	public void setColumns(ArrayList columns) {
		this.columns = columns;
	}
}
